package server;

import java.io.IOException;

import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.server.PropertyHandlerMapping;
import org.apache.xmlrpc.server.XmlRpcServer;
import org.apache.xmlrpc.server.XmlRpcServerConfigImpl;
import org.apache.xmlrpc.webserver.WebServer;

import exceptions.MissingParametersException;

/**
 * An RPC Server that allows remote access to the bot
 * 
 * 
 */
public class RPCServer {
   public static void main(final String[] args) throws MissingParametersException, XmlRpcException, IOException {
	  if (args.length != 2)
		 throw new MissingParametersException("Parameters missing");
	  WebServer webServer = new WebServer(Integer.parseInt(args[0]));
	  webServer.setParanoid(false);
	  // webServer.acceptClient(args[1]);

	  XmlRpcServer xmlRpcServer = webServer.getXmlRpcServer();

	  PropertyHandlerMapping phm = new PropertyHandlerMapping();
	  phm.addHandler("RPCHandler", commandhandlers.RPCHandler.class);
	  phm.setAuthenticationHandler(new BotAuthenticationHandler());
	  xmlRpcServer.setHandlerMapping(phm);

	  XmlRpcServerConfigImpl serverConfig = (XmlRpcServerConfigImpl) xmlRpcServer.getConfig();
	  serverConfig.setEnabledForExtensions(false);

	  webServer.start();
   }
}
